/**
 * 
 */
package com.precisosoft.mathematize.server.guice;

import com.google.inject.servlet.ServletModule;
import com.gwtplatform.dispatch.server.guice.DispatchServiceImpl;
import com.gwtplatform.dispatch.shared.ActionImpl;
import com.gwtplatform.dispatch.shared.SecurityCookie;
import com.precisosoft.mathematize.server.servlet.LoginServlet;
import com.precisosoft.mathematize.server.servlet.RegisterServlet;
import com.precisosoft.mathematize.shared.SharedTokens;

/**
 * @author jewettdx
 *
 */
public class DispatchServletModule extends ServletModule {

	  @Override
	  public void configureServlets() {
	    bindConstants();
	    bindFilters();
	    bindServlets();
	  }

	  protected void bindConstants() {
	    // Protect against XSRF attacks - securityCookieName = "JSESSIONID";
	    bindConstant().annotatedWith(SecurityCookie.class).to(SharedTokens.securityCookieName);
	  }

	  protected void bindFilters() {
	  }

	  /*

	  protected void bindServlets() {
	    // For GWT 2.0.4
	    serve("/serendipity/" + ActionImpl.DEFAULT_SERVICE_NAME).with(
	        DispatchServiceImpl.class);
	  }

	  */

	  // <!--
	  // This Guice listener hijacks all further filters and servlets.
	  // Extra filters and servlets have to be configured in your
	  // ServletModule#configureServlets() by calling
	  // serve(String).with(Class<? extends HttpServlet>) and
	  // filter(String).through(Class<? extends Filter).
	  // -->

	  public static final String DEFAULT_SERVICE_PATH = "/";
	  public static final String REPORTS_SERVICE_PATH = "/reports/*";
	  public static final String FILE_UPLOAD_SERVICE_PATH = "/upload";
	  public static final String FILE_DOWNLOAD_SERVICE_PATH = "/download/*";
	  public static final String MOBILE_SERVICE_PATH = "/mobile/*";

	  protected void bindServlets() {
	    // For GWT 2.1.1
	    serve(DEFAULT_SERVICE_PATH + ActionImpl.DEFAULT_SERVICE_NAME).with(
	        DispatchServiceImpl.class);

	    // This registers a servlet (subclass of HttpServlet) called ReportServlet
	    // to serve any web requests using a path-style syntax (as you would in web.xml).
//	    serve(REPORTS_SERVICE_PATH).with(ReportServlet.class);
//	    serve(FILE_UPLOAD_SERVICE_PATH).with(FileUploadServlet.class);
//	    serve(FILE_DOWNLOAD_SERVICE_PATH).with(FileDownloadServlet.class);
	    serve(MOBILE_SERVICE_PATH).with(LoginServlet.class);
	    serve(MOBILE_SERVICE_PATH).with(RegisterServlet.class);
	  }

}
